package com.wisdudu.blank.ui.user;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

import com.wisdudu.blank.R;
import com.wisdudu.blank.databinding.FragmentGenderCheckBinding;
import com.wisdudu.frame.base.BaseFragment;

/**
 * Created by ypp on 2016/8/29.
 */
public class UserSexCheckFragment extends BaseFragment {
    private static final String TAG = "UserSexCheckFragment";
    public static final String EXTRA_SEX = "sex";
    private UserSexCheckVM userSexCheckVM;

    @Override
    protected View initBinding(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        FragmentGenderCheckBinding mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_gender_check, container, false);
        userSexCheckVM = new UserSexCheckVM(this,getArguments().getInt(EXTRA_SEX, 0));
        mBinding.setViewModel(userSexCheckVM);
        return mBinding.getRoot();
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initToolbar(getToolbar(), "修改性别");
    }

    @Override
    protected void initMenuToolbar(Toolbar toolbar) {
        super.initMenuToolbar(toolbar);
        toolbar.inflateMenu(R.menu.menu_fragment_save);
        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.menu_save:
                        confirm();
                        break;
                }
                return true;
            }
        });
    }

    private void confirm() {
        userSexCheckVM.confirm();
    }
}
